package Controller.GestionGroupe;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import Controller.BDD.GestionGroupeBDD;
import Controller.BDD.GestionUserBDD;
import Model.Groupe;

/**
 * Servlet implementation class CreerGroupe
 */
@WebServlet("/ChargerEditerGroupe")
public class ChargerEditerGroupe extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ChargerEditerGroupe() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		
		String urlVue = "GestionGroupe/EditerGroupe.jsp";
		
		int id 		   =  Integer.parseInt((String) request.getParameter("id"));
		String message ="";
		
		
		Groupe groupe = GestionGroupeBDD.recupererGroupeParID(id);
		// Recuperer info par l'id
		if(groupe == null) message = "Le groupe n'existe plus !";
		
		int nbrUser = GestionUserBDD.recupererListeUsers().size();
		if( nbrUser  < 10) nbrUser = 10;
		
		
		request.setAttribute("Groupe", groupe);
		request.setAttribute("nbrUser", GestionUserBDD.recupererListeUsers().size());
		request.getRequestDispatcher(urlVue).forward(request, response);
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
